package com.dubbo.platform.user.remote;


import com.alibaba.dubbo.config.annotation.Service;
import com.alibaba.dubbo.rpc.RpcContext;
import com.dubbo.platform.user.contract.IUserService;
import com.dubbo.platform.user.entity.User;


import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;

/**
 *
 */
@Service(version = "1.0.0")
public class UserServiceImpl implements IUserService {
    public List<User> getUserInfos(List<Long> uids)
    {
        List<User> users = new ArrayList<>();
        for(Long uid : uids){
            User tmp = new User();
            tmp.setUid(uid);
            tmp.setMobile("13511111111");
            tmp.setNickname("昵称" + uid);
        }

        return users;
    }

    public User getUserInfo(Long uid){
        User user = new User();
        user.setUid(uid);
        user.setMobile("13511111111");
        user.setNickname("昵称" + uid);
        return user;
    }

    @Override
    public CompletableFuture<String> sayHello(String name) {
        RpcContext savedContext = RpcContext.getContext();
        // 建议为supplyAsync提供自定义线程池，避免使用JDK公用线程池
        return CompletableFuture.supplyAsync(() -> {
            System.out.println(savedContext.getAttachment("consumer-key1"));
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return "async response from provider.";
        });
    }
}